package com.oritsh.hl7;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.app.Connection;
import ca.uhn.hl7v2.app.Initiator;
import ca.uhn.hl7v2.llp.LLPException;
import ca.uhn.hl7v2.model.Message;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: zarra
 * Date: 14-3-15
 * Time: 上午11:12
 * Copyright Shanghai Orient Rain Information Technology Co.,Ltd.
 */
public class Client implements  AutoCloseable {
    private Connection connection;

    public Client(Connection connection){
        this.connection = connection;
    }

    public Message sendAndReceive(Message msg) throws LLPException, IOException, HL7Exception {
        Initiator initiator = connection.getInitiator();
        Message response = initiator.sendAndReceive(msg);
        return response;
    }

    public void close(){
        this.connection.close();
    }
}
